package be.jhd.downloader;

import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import junit.framework.Assert;

import org.junit.Test;

import be.jhd.repository.Artifact;
import be.jhd.repository.DownloadException;
import be.jhd.repository.Downloader;
import be.jhd.repository.EarArtifact;
import be.jhd.repository.nexus.UrlBuilderImpl;

public class DownloaderTestIntegration {

	@Test
	public void download() throws DownloadException{
		Artifact artifact = new EarArtifact("belpic", "webconfiguration-as-ear", "3.0.4");
		
		UrlBuilderImpl builder = mock(UrlBuilderImpl.class);
		doReturn("http://10.0.1.210:8081/nexus/service/local/artifact/maven/redirect?g=belpic&a=webconfiguration-as-ear&v=3.0.4&r=releases&p=ear").when(builder).buildUrl(artifact);
		
		Downloader downloader = new Downloader(builder);
		
		byte[] response = downloader.download(artifact);
		
		Assert.assertNotNull(response);
	}
	
	@Test(expected=DownloadException.class)
	public void inexistingDownload() throws DownloadException{
		Artifact artifact = new EarArtifact("belpic", "webconfiguration-as-ear", "9.9.9");
		
		UrlBuilderImpl builder = mock(UrlBuilderImpl.class);
		doReturn("http://10.0.1.210:8081/nexus/service/local/artifact/maven/redirect?g=belpic&a=webconfiguration-as-ear&v=9.9.9&r=releases&p=ear").when(builder).buildUrl(artifact);
		
		Downloader downloader = new Downloader(builder);
		
		downloader.download(artifact);
		
	}
}
